//
//  FeedbackViewController.m
//  MeetCard
//
//  Created by timtian on 16/12/6.
//  Copyright © 2016年 timtian. All rights reserved.
//

#import "FeedbackViewController.h"
#import "LMFeedbackQuestion.h"
#import "LMFeedBackTextView.h"
#import "LMCellView.h"

@interface FeedbackViewController ()
@property (nonatomic,strong) UIScrollView *contentView;

@property(nonatomic, strong) LMFeedbackQuestion *likeContentQ;

@property(nonatomic, strong) LMFeedbackQuestion *likeDesignQ;

@property(nonatomic, strong) LMFeedBackTextView *feedBackTextView;

@property(nonatomic, strong) LMCellView *emailTextView;

@property(nonatomic, strong) LMButton *commitBtn;

@end

@implementation FeedbackViewController

#pragma mark - 生命周期


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitle:@"问题反馈"];

    [self createUI];
    [self updateView];
    [self setLayout];
}


#pragma mark - Event

-(void)commitBtnClick {
    
    [MBProgressHUD showText:@"提交反馈" onView:nil];
}

#pragma mark - Public
#pragma mark-- private
- (void)createUI {
    
    self. contentView.frame = CGRectMake(0, 64, __kScreenWidth, __kScreenHeight - 64);
    self.contentView.backgroundColor = HGCOLOR(@"ffffff");
    [self.view addSubview:self.contentView];
    
    [self.contentView addSubview:self.likeContentQ];
    [self.contentView addSubview:self.likeDesignQ];
    [self.contentView addSubview:self.feedBackTextView];

    [self.contentView addSubview:self.commitBtn];
}

- (void)setLayout {
    
    self.likeContentQ.top = 0;
    self.likeDesignQ.top = self.likeContentQ.bottom;
    self.feedBackTextView.top = self.likeDesignQ.bottom;
    

    
    self.commitBtn.centerX = self.view.width * 0.5;
    self.commitBtn.top = self.feedBackTextView.bottom + MK_PADDING_30 * 2 * __kwRatio;
    

   self.contentView.contentSize = CGSizeMake(self.contentView.width, self.commitBtn.bottom + MK_PADDING_30 * __kwRatio);
}

-(void)updateView {
    
    BOOL canCommit = self.likeDesignQ.feedBackType && self.likeContentQ.feedBackType && self.feedBackTextView.text.length ;
    self.commitBtn.enabled = canCommit;
    
}

#pragma mark - 数据源和代理方法
#pragma mark - UIView -> 下面放继承自UIView的方法
#pragma mark - set方法和get方法
-(UIScrollView *)contentView{
    if (_contentView == nil) {
        _contentView = [[UIScrollView alloc]init];
    }
    return _contentView;
}
-(LMFeedbackQuestion *)likeContentQ {
    if (_likeContentQ == nil) {
        _likeContentQ = [LMFeedbackQuestion feedbackQuestionWithTitle:@"A、是否满意我们的技术"];
        __weak typeof(self) weakSelf = self;
        [_likeDesignQ setFeedTypeChangedBlock:^(LMFeedbackType feedBackType) {
            [weakSelf updateView];
        }];
    }
    return _likeContentQ;
}

-(LMFeedbackQuestion *)likeDesignQ {
    if (_likeDesignQ == nil) {
        _likeDesignQ = [LMFeedbackQuestion feedbackQuestionWithTitle:@"B、是否喜欢我们的服务"];
        __weak typeof(self) weakSelf = self;
        [_likeDesignQ setFeedTypeChangedBlock:^(LMFeedbackType feedBackType) {
            [weakSelf updateView];
        }];
    }
    return _likeDesignQ;
}

-(LMFeedBackTextView *)feedBackTextView {
    if (_feedBackTextView == nil) {
        _feedBackTextView = [LMFeedBackTextView feedbackTextViewWithPlaceHolder:@"请告诉我们你的评价或者想反馈的意见 (必填)"];
        __weak typeof(self) weakSelf = self;
        [_feedBackTextView setTextDidChangeBlock:^(NSString *text) {
            [weakSelf updateView];
        }];
    }
    return _feedBackTextView;
}



-(LMButton *)commitBtn {
    if (_commitBtn == nil) {
        _commitBtn = [LMButton lm_buttonWithType:LMButtonTypeMove title:@"提交反馈"];
        [_commitBtn addTarget:self action:@selector(commitBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _commitBtn;
}

@end
